package com.ruoyi.share.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayDataBillAccountlogQueryRequest;
import com.alipay.api.request.AlipayDataBillSellQueryRequest;
import com.alipay.api.response.AlipayDataBillAccountlogQueryResponse;
import com.alipay.api.response.AlipayDataBillSellQueryResponse;
import com.ruoyi.share.service.AliPayOATGPService;
import lombok.Setter;
import org.springframework.stereotype.Service;

@Service
public class AliPayOATGPServiceImpl implements AliPayOATGPService {
    /**
     *  支付宝商家账户卖出交易查询
     *  为支付宝商家提供支付宝账户卖出交易信息，供对账使用。
     *  2021年11月17日14:45:55
     *  nlx 654008850@qq.com
     */
    @Override
    public void doPost(JSONObject params) throws AlipayApiException {
        /**请求参数
         参数	类型	是否必填	最大长度	描述	示例值
         start_time	String	必选	20	卖出交易流水创建时间的起始范围	2019-01-01 00:00:00
         end_time	String	必选	20	卖出交易流水创建时间的结束范围。与起始时间间隔不超过31天。查询结果为起始时间至结束时间的左闭右开区间	2019-01-02 00:00:00
         alipay_order_no	String	可选	255	支付宝交易流水号。如果查询参数中指定流水号，则只查询流水号相关的记录	20190101***
         merchant_order_no	String	可选	255	商户交易号。如果查询参数中指定交易号，则只查询相关的记录	TX***
         store_no	String	可选	255	门店编号，模糊搜索	门店1
         page_no	String	可选	8	分页号，从1开始	1
         page_size	String	可选	8	分页大小1000-2000，默认2000	2000
         */
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
        AlipayDataBillSellQueryRequest request = new AlipayDataBillSellQueryRequest();
        request.setBizContent("{" +
                "\"start_time\":\"2019-01-01 00:00:00\"," +
                "\"end_time\":\"2019-01-02 00:00:00\"," +
                "\"alipay_order_no\":\"20190101***\"," +
                "\"merchant_order_no\":\"TX***\"," +
                "\"store_no\":\"门店1\"," +
                "\"page_no\":\"1\"," +
                "\"page_size\":\"2000\"" +
                "  }");
        AlipayDataBillSellQueryResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }

    /**
     *  支付宝商家账户账务明细查询
     *  为支付宝商家提供支付宝账户的账务流水信息，供对账使用
     *  2021年11月17日14:45:55
     *  nlx 654008850@qq.com
     */
    @Override
    public void get(JSONObject params) throws AlipayApiException {
        /**请求参数
         参数	类型	是否必填	最大长度	描述	示例值
         start_time	String	必选	20	账务流水创建时间的起始范围	2019-01-01 00:00:00
         end_time	String	必选	20	账务流水创建时间的结束范围。与起始时间间隔不超过31天。查询结果为起始时间至结束时间的左闭右开区间	2019-01-02 00:00:00
         alipay_order_no	String	特殊可选	255	支付宝订单号，通过支付宝订单号精确查询相关的流水明细，商户订单号与支付宝订单号互斥	20190101***
         merchant_order_no	String	特殊可选	255	商户订单号，通过商户订单号精确查询相关的流水明细，商户订单号与支付宝订单号互斥	TX***
         page_no	String	可选	8	分页号，从1开始	1
         page_size	String	可选	8	分页大小1000-2000，默认2000	2000

         */
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do","app_id","your private_key","json","GBK","alipay_public_key","RSA2");
        AlipayDataBillAccountlogQueryRequest request = new AlipayDataBillAccountlogQueryRequest();
        request.setBizContent("{" +
                "  \"start_time\":\"2019-01-01 00:00:00\"," +
                "  \"end_time\":\"2019-01-02 00:00:00\"," +
                "  \"alipay_order_no\":\"20190101***\"," +
                "  \"merchant_order_no\":\"TX***\"," +
                "  \"page_no\":\"1\"," +
                "  \"page_size\":\"2000\"" +
                "}");
        AlipayDataBillAccountlogQueryResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }
}
